package com.sailfish.mq.listener;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class MessageListener {

    @KafkaListener(topics = {"topic-sync"}, groupId = "pg2.0TOpg3.0")
    public void listener(ConsumerRecord<String, String> record) {
        //获取消息
        String message = record.value();
        //消息偏移量
        long offset = record.offset();
        System.out.println("读取的消息：" + message + "\n当前偏移量：" + offset);
    }

    @KafkaListener(topics = {"topic-sync3-a"}, groupId = "pg3.0TOpg2.0")
    public void listener3(ConsumerRecord<String, String> record) {
        //获取消息
        String message = record.value();
        //消息偏移量
        long offset = record.offset();
        System.out.println("读取的消息：" + message + "\n当前偏移量：" + offset);
    }
}
